package com.xqboss.apps.controller.game;

import com.xqboss.apps.enums.game.GameCodeEnum;
import com.xqboss.apps.service.game.GameService;
import com.xqboss.apps.vo.game.materialStrike.GameVo;
import com.xqboss.common.core.controller.BaseController;
import com.xqboss.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 这个controller可以定义游戏的一些公共接口
 *
 * @author ljh
 * @date 2024-1-30
 */
@Slf4j
@RestController
@RequestMapping("/game")
@Api(tags = "游戏")
public class GameController extends BaseController {

    @Autowired
    private GameService gameService;

    @ApiOperation("游戏列表页")
    @GetMapping
    public R<List<GameVo>> list() {
        return gameService.gameList(getUserId());
    }


    @ApiOperation(value = "校验用户是否具有权限",notes = "校验用于是否具有权限",httpMethod = "GET")
    @GetMapping("/verifyUserId/{gameCode}")
    public R<Boolean> verifyUserId(@ApiParam(name = "gameCode",value = "游戏标识",readOnly = true) @PathVariable GameCodeEnum gameCode) {
        Long loginUserId = null;
        try{
            loginUserId = getUserId();
            return R.ok(gameService.verifyUserId(gameCode,getUserId()));
        }catch (Exception e) {
            log.error("校验用户[{}]玩游戏[{}]是否具有权限异常：",loginUserId,gameCode,e);
            return R.fail(e.getMessage());
        }
    }

}
